package terminal.utility;

import javax.swing.*;
import java.util.*;
import java.util.Timer;

public class Main {

    public static JLabel label = null;

    public static void main(String args[]) {
        java.util.Timer t = new Timer();
        t.scheduleAtFixedRate(new MyCounter(), 1000, 1000);


        Calendar cal = Calendar.getInstance();
        /*cal.set(Calendar.HOUR_OF_DAY, new Date().getHours());
        cal.set(Calendar.MINUTE, new Date().getMinutes());*/
        cal.set(Calendar.SECOND, new Date().getSeconds());


        Date d = new Date();
        System.out.println("1: "+ d);
        System.out.println("2: "+ cal.getTime());
        
        if(cal.getTime().toString().equals(d.toString())){
            System.out.println("same");
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                JFrame frame = new JFrame();
                label = new JLabel();
                label.setText("Time: 0");
                frame.add(label);
                frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
                frame.setBounds(0, 0, 300, 88);
                frame.setVisible(true);
            }
        });
    }

    static class MyCounter extends TimerTask {

        private int count = 0;

        public void run() {
            if (label != null) {
                label.setText("Time: " + (++count));

                System.out.println(Calendar.getInstance().getTime().getSeconds());
            }
        }
    }
}